// *************************************************************************
//
//                                JOST
//
//               Copyright (C) 2007 by Angelo Corsaro.
//                       <angelo.corsaro@gmail.com>
//                          All Rights Reserved.
//
//   Permission to use, copy, modify, and distribute this software and
//   its  documentation for any purpose is hereby  granted without fee,
//   provided that the above copyright notice appear in all copies and
//   that both that copyright notice and this permission notice appear
//   in  supporting  documentation. I don't make  any  representations
//   about the  suitability  of this  software for any  purpose. It is
//   provided "as is" without express or implied warranty.
//
//
// *************************************************************************
//  
// *************************************************************************
#ifndef _JOST_OBJECT_H_
#define _JOST_OBJECT_H_

#include <string>
#include <map>

#include "jost/Value.hpp"

namespace jost {
    class Object;
}

/**
 * The class <code>Object</code> represents a JSON Object, which is
 * made of a collection of named fields.<br>
 *
 * @author Angelo Corsaro <mailto:angelo.corsaro@gmail.com>
 * @version 0.1
 */ 
class jost::Object : 
    public virtual jost::Value {
public:
    typedef std::map<std::string, jost::Value*> ValueMap_t;
    typedef ValueMap_t::const_iterator const_iterator;
    typedef ValueMap_t::iterator iterator;
  
public:

    /**
     * Creates a new <code>Object</code>.
     */
    Object() throw();

    /**
     * Destroys this <code>Object</code> and its contained
     * <code>Value<code>s.
     */
    virtual ~Object() throw();
  
public:
    /**
     * Get a field provided its name.
     *
     * @param field the name of the object field.
     * 
     * @return the <code>Value</code> associated with the given field
     * name.
     * 
     * @exception jost::UnknownField when the field name is not
     * present in the given <code>Object</code>.
     */ 
    inline jost::Value* 
    get_field(const std::string& field) 
	throw(jost::UnknownField);

    /**
     * Set a field with a specific <code>Value</code>.
     *
     * @param name the field name
     * @param value the filed value
     * @return the previous value associated with the field name.
     */ 
    inline  jost::Value*
    set_field(const std::string& name, jost::Value* value) 
	throw(); 
  

    /**
     * Generates the JSON serialization for the current
     * <code>Object</code>.
     * 
     * @return a string representing the JSON stream for the given
     * object.
     */ 
    virtual std::string serialize() throw();

    
public:
    inline iterator begin() throw();
    inline iterator end() throw();

    inline const_iterator begin() const throw();
    inline const_iterator end() const throw();

private:
    ValueMap_t field_map_;
};

#include "Object.inl"

#endif /*_JOST_OBJECT_H_*/
